// SEmailLibDemo.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include "SEmailLib/MailMan.h"
#include "SEmailLib/MIMEMail.h"

int main(int argc, char* argv[])
{
	if (argc < 11)
	{
		printf("USAGE:\n  %s usr pwd smtphost port enablessl(y|n) from to charset subject content attachfile", argv[0]);
		return 0;
	}

	std::string usr(argv[1]),pwd(argv[2]),smtphost(argv[3]);
	unsigned int smtphostport = atoi(argv[4]);
	bool bEnableSSL = (argv[5][0] == 'y' || argv[5][0] == 'Y');
	std::string from(argv[6]), to(argv[7]), charset((argv[8]));
	std::string subject(argv[9]), content(argv[10]), attachfile(argv[11]);
	

 	CMailMan mailman;
	mailman.SetSmtpHost( smtphost );
	mailman.SetSmtpPort(smtphostport);
	mailman.SetSmtpUsername( usr );
	mailman.SetSmtpPassword( pwd );
 	mailman.EnableSmtpSSL(bEnableSSL);
	
	CMIMEMail mail;
	mail.SetCharset(charset);
	mail.SetFrom( from );
	mail.SetTo( to );
	mail.SetSubject(subject);
	mail.SetContent(content);
	mail.SetAttach(attachfile);
	
	if(mailman.SendMail(mail))
		printf("mail sent!\n");
	else
		printf("failed!\n");

	return 0;
}

